﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _1b
{
    
    public partial class Form1 : Form
    {
        int sum = 0;//正确答案
        int grade = 0;//得分
        int round = 0;//第几轮
        string comment = "";//评价
        public void getAddAndSubNum(ref int addNum, ref int subNum)
        {
            Random rd = new Random();
            addNum = rd.Next(1000);
            subNum = rd.Next(addNum);
        }
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }
        //生成新题目
        private void nextQuestion()
        {

            int addNum = 0;
            int subNum = 0;
            getAddAndSubNum(ref addNum, ref subNum);
            //随机生成0/1，分别代表减法和加法
            Random rdGetSign = new Random();
            int sign = rdGetSign.Next(2);
            if (sign == 1)//加法
            {
                this.labelQus.Text = addNum.ToString() + "+" + subNum.ToString();
                sum = addNum + subNum;
            }
            else//减法
            {
                this.labelQus.Text = addNum.ToString() + "-" + subNum.ToString();
                sum = addNum - subNum;
            }

        }
        private void buttonStart_Click(object sender, EventArgs e)
        {
            this.timer1.Enabled = true;
            int addNum = 0;
            int subNum = 0;
            getAddAndSubNum(ref addNum, ref subNum);
            //随机生成0/1，分别代表减法和加法
            Random rdGetSign = new Random();
            int sign = rdGetSign.Next(2);
            if (sign == 1)//加法
            {
                this.labelQus.Text = addNum.ToString() + "+" + subNum.ToString();
                sum = addNum + subNum;
            }
            else//减法
            {
                this.labelQus.Text = addNum.ToString() + "-" + subNum.ToString();
                sum = addNum - subNum;
            }
            this.buttonStart.Visible = false; 

        }

        private void buttonSure_Click(object sender, EventArgs e)
        {
            //检测答案是否正确
            int myAnswer = Int32.Parse(this.textBox1.Text);
            if(myAnswer==sum)
            {
                MessageBox.Show("输入正确，太牛逼了!");
                this.grade += 10;
                this.round += 1;
                if(this.round==10)//出十题
                {
                    this.timer1.Stop();
                    this.buttonSure.Visible = false;
                    if (this.grade < 60)
                        this.comment = "再接再厉，小老弟";
                    else if (this.grade == 60 || this.grade == 70)
                        this.comment = "还可以，勉强及格";
                    else
                        this.comment = "挺优秀啊";
                    MessageBox.Show("你的最终得分是:" + this.grade + "," + this.comment);
                }
                nextQuestion();
                this.timer1.Start();
            }
            else
            {
                MessageBox.Show("有点菜啊，小老弟,再试试");
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        { 
            nextQuestion();
            this.round += 1;
            if(this.round==10)
            {
                this.timer1.Stop();
                this.buttonSure.Visible = false;
                if (this.grade < 60)
                    this.comment = "再接再厉，小老弟";
                else if (this.grade == 60 || this.grade == 70)
                    this.comment = "还可以，勉强及格";
                else
                    this.comment = "挺优秀啊";
                MessageBox.Show("你的最终得分是:" + this.grade+","+this.comment);

            }
        }
    }
}
